﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Saker.Kernel.BLL;
using Saker.Kernel.Model;
using System.Text;
using System.Reflection;
using Saker.Utility;

namespace Saker.Web.Boss.Sys.Depart
{
    /// <summary>
    /// DepartHandler 的摘要说明
    /// </summary>
    public class DepartHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            List<DepartTreeViewNode> nodes = new List<DepartTreeViewNode>();
            string id = HttpUtility.UrlDecode(context.Request.Params["id"]);
            IEnumerable<SysDepartment> departList=new SysDepartmentBLL().GetAllByParentID(id==null?0:int.Parse(id));
            foreach (SysDepartment depart in departList)
            {
                DepartTreeViewNode node = new DepartTreeViewNode(depart.DepartID.ToString(),depart.ChildCount==0?false:true,depart.DepartName);
                if (node.isParent)
                {
                    node.iconOpen = "/images/tree/server_group_open.png";
                    node.iconClose = "/images/tree/server_group_close.png";
                }
                else
                {
                    node.icon ="/images/tree/server.png";
                }
                nodes.Add(node);
            }
            context.Response.ContentType = "application/json";
            context.Response.Write(JsonHelper.objectListToJson(nodes));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}